var index = 0;
$(function () {
    // 获取Banner图
    getBanner();

    // 获取名校交流
    getSchoolDynamics();

    // 获取时政要闻
    getNews();

    // 获取浙江新闻
    getNews2();

    // 获取公告
    getNews3();
})

// 获取Banner
function getBanner() {
    var data = {
        type: "FIRST_PAGE"
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getBanner", getBanner_fun);
}

// 获取banner图
function getBanner_fun(res) {
    // console.log(res);
    if (res.status == "SUCCESS") {
        var imgLists = res.obj;
        $.each(imgLists, function (i, imgList) {
            if (i == 0) {
                $(".carousel-indicators").append('<li data-target="#carousel-example-generic" data-slide-to="' + i + '" class="active"></li>');
                $(".carousel-inner").append('<div class="item active"> ' +
                    '<img src="' + imgList.pic + '" alt="..." style="height:460px;width:100%"> ' +
                    '<div class="carousel-caption">' +
                    imgList.title +
                    '</div> ' +
                    '</div>');
            }
            else {
                $(".carousel-indicators").append('<li data-target="#carousel-example-generic" data-slide-to="' + i + '"></li>');
                $(".carousel-inner").append('<div class="item"> ' +
                    '<img src="' + imgList.pic + '" alt="..." style="height:460px;width:100%"> ' +
                    '<div class="carousel-caption">' +
                    imgList.title +
                    '</div> ' +
                    '</div>');
            }
        })
    }
}

// 获取学校动态
function getSchoolDynamics() {
    var data = '{"page":"' + index + '","size":"' + 5 + '","type":"DYNAMICS"}';
    AjaxSubmit("GET", JSON.parse(data), basePath + "/common/firstPage/getSchoolDynamics", getSchoolDynamics_fun);
}

// 名校交流
function getSchoolDynamics_fun(res) {
    var schoolLists = res.obj.content;
    // console.log(res);
    if (res.status == "SUCCESS") {
        $(".mxjl").find(".xinwen").find("img").attr("src", res.obj.content[0].pic);
        $(".mxjl").find(".xinwen").find(".bigNew").find(".bigNewFont").html(res.obj.content[0].title);
        $(".mxjl").find(".xinwen").find(".bigNew").find(".smallNewFont").html(res.obj.content[0].content);
        $(".mxjl").find(".xinwen").find(".bigNew").find(".time").html(changeTime2(res.obj.content[0].creatTime));
        $.each(schoolLists, function (i, schoolList) {
            if (i != 0) {
                if (i == schoolLists.length - 1) {
                    $(".mxjl").find(".xinwen").find("ul").append('<li class="clearfix last-li"> ' +
                        '<p class="bigTitle">' + schoolList.title + '</p> ' +
                        '<div class="time pull-right">' +
                        changeTime2(schoolList.creatTime) +
                        '</div> </li>');
                } else {
                    $(".mxjl").find(".xinwen").find("ul").append('<li class="clearfix"> ' +
                        '<p class="bigTitle">' + schoolList.title + '</p> ' +
                        '<div class="time pull-right">' +
                        changeTime2(schoolList.creatTime) +
                        '</div> </li>');
                }
            }
        })
    }
}

function getNews() {
    var data = {
        typeId: 1,
        page: index,
        size: 5
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNews", getNews_fun);
}

// 时政要闻
function getNews_fun(res) {
    var newsLists = res.obj.content;
    // console.log(res);
    if (res.status == "SUCCESS") {
        $(".szyw").find(".shizheng").find("img").attr("src", res.obj.content[0].pic);
        $(".szyw").find(".shizheng").find(".bigNew").find(".bigNewFont").html(res.obj.content[0].title);
        $(".szyw").find(".shizheng").find(".bigNew").find(".smallNewFont").html(res.obj.content[0].text);
        $(".szyw").find(".shizheng").find(".bigNew").find(".time").html(changeTime2(res.obj.content[0].creatTime));
        $.each(newsLists, function (i, newsList) {
            if (i != 0) {
                if (i == newsLists.length - 1) {
                    $(".szyw").find(".shizheng").find("ul").append('<li class="clearfix last-li"> ' +
                        '<div class="pull-left News">' +
                        newsList.title +
                        '</div> ' +
                        '<div class="pull-right time">' +
                        changeTime2(newsList.creatTime) +
                        '</div> </li>');
                } else {
                    $(".szyw").find(".shizheng").find("ul").append('<li class="clearfix"> ' +
                        '<div class="pull-left News">' + newsList.title + '</div> ' +
                        '<div class="pull-right time">' +
                        changeTime2(newsList.creatTime) +
                        '</div> </li>');
                }
            }
        })
    }
}

function getNews2() {
    var data = {
        typeId: 2,
        page: index,
        size: 5
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNews", getNews2_fun);
}

// 浙江新闻
function getNews2_fun(res) {
    var newsLists2 = res.obj.content;
    // console.log(res);
    if (res.status == "SUCCESS") {
        $(".zjxw").find(".shizheng").find(".outimg").attr("src", res.obj.content[0].pic);
        $(".zjxw").find(".shizheng").find(".bigNew").find(".bigNewFont").html(res.obj.content[0].title);
        $(".zjxw").find(".shizheng").find(".bigNew").find(".smallNewFont").html(res.obj.content[0].text);
        $(".zjxw").find(".shizheng").find(".bigNew").find(".time").html(changeTime2(res.obj.content[0].creatTime));
        $.each(newsLists2, function (i, newsList2) {
            if (i != 0) {
                if (i == newsLists2.length - 1) {
                    $(".zjxw").find(".shizheng").find(".bigNew").find("ul").append('<li class="clearfix last-li"> ' +
                        '<img src="' + newsList2.pic + '" alt="" class="pull-left img-rounded smallimg"> ' +
                        '<div class="pull-left News">' +
                        newsList2.title +
                        '</div> ' +
                        '<div class="pull-right time">' +
                        changeTime2(newsList2.creatTime) +
                        '</div> </li>');
                } else {
                    $(".zjxw").find(".shizheng").find(".bigNew").find("ul").append('<li class="clearfix"> ' +
                        '<img src="' + newsList2.pic + '" alt="" class="pull-left img-rounded smallimg"> ' +
                        '<div class="pull-left News">' +
                        newsList2.title +
                        '</div> ' +
                        '<div class="pull-right time">' +
                        changeTime2(newsList2.creatTime) +
                        '</div> </li>');
                }
            }
        })
    }
}

function getNews3() {
    var data = {
        typeId: 3,
        page: index,
        size: 5
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNews", getNews3_fun);
}

// 公告
function getNews3_fun(res) {
    var newsLists3 = res.obj.content;
    console.log(res);
    if (res.status == "SUCCESS") {
        $.each(newsLists3, function (i, newsList3) {
            $(".gg").find(".gonggao").find("ul").append('<li>' + newsList3.title + '</li>');
        })
    }
}